/*
 * Copyright 2010 Biz-e (info@biz-e.nl)
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package nl.biz_e.gwt.baselib.ui.client.menu;

import java.util.List;

import nl.biz_e.gwt.baselib.ui.client.IAppManager;
import nl.biz_e.gwt.baselib.ui.client.panels.PanelManager;

/**
 * TODO: Write type comment
 * 
 * @author Joost A. Bloemsma
 * 
 */
public abstract class AbstractMenuPanelManager implements IMenuPanelManager {
	private final PanelManager panelMgr;
	private final IAppManager appMgr;
	private final IMenuPanel menuPanel;
	private boolean isLoggedIn = false;
	private String userName = "";
	
	public AbstractMenuPanelManager(PanelManager panelMgr) {
		this.panelMgr = panelMgr;
		this.appMgr = panelMgr.getAppManager();
		this.menuPanel = new MenuPanel(this);
	}
	
	/**
	 * {@inheritDoc}
	 */
	public void addMenuItems(List<IMenuItem> items) {
		if (items == null)
			return;
		if (items.size() > 0) {
			menuPanel.addMenuItems(items);
			menuPanel.rebuildMenu();
		}
	}
	
	/**
	 * {@inheritDoc}
	 */
	public void addMenuItem(IMenuItem menuItem) {
		menuPanel.addMenuItem(menuItem);
		menuPanel.rebuildMenu();
	}
	
	/**
	 * {@inheritDoc}
	 */
	@Override
	public IAppManager getAppManager() {
		return this.appMgr;
	}
	
	/**
	 * {@inheritDoc}
	 */
	@Override
	public boolean isLoggedIn() {
		return isLoggedIn;
	}
	
	/**
	 * {@inheritDoc}
	 */
	@Override
	public void setLoggedIn(boolean loggedIn) {
		this.isLoggedIn = loggedIn;
	}
	
	/**
	 * {@inheritDoc}
	 */
	@Override
	public void setMenuItemSelected(IMenuItem item, boolean selected) {
		this.menuPanel.setMenuItemSelected(item, selected);
	}
	
	/**
	 * {@inheritDoc}
	 */
	@Override
	public void setOnlySelectedMenuItem(IMenuItem item) {
		this.menuPanel.setOnlySelectedMenuItem(item);
	}
	
	/**
	 * {@inheritDoc}
	 */
	@Override
	public void setUserName(String userName) {
		this.userName = userName;
	}
	
	/**
	 * {@inheritDoc}
	 */
	public String getUserName() {
		return this.userName;
	}
	
}
